<!--拌和站---拌合站设置-->
<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-12-06 13:13:25
 * @LastEditors: 卡卡 1071780426@qq.com
 * @LastEditTime: 2023-03-27 16:07:31
 * @FilePath: \backstage - 副本\src\views\aa.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class="department" id="mixingPlant">
        <!-- 左侧部门管理 -->
        <div class="structureTree" v-if="treelength">
            <div class="structureTree_title">
                <div>组织机构</div>
                <div></div>
            </div>
            <tree :treeData="treeData" :checkData="checkData" name="currencyList" nodeKey="fCompanyid"
                @getTreeInfo="handleNodeClick" :defaultProps="defaultProps">
            </tree>
        </div>
        <!-- 右侧 -->
        <div class="department_right">
            <!-- 机构名称 -->
            <el-breadcrumb :title="showName"></el-breadcrumb>
            <!-- 顶部导航栏 -->
            <div class="mechanism_nav ">
                <!-- 左侧 -->
                <div class="mechanism_nav_left ">
                </div>
                <!-- 顶部按钮 -->
                <div class="print" style="justify-content: flex-end">
                    <!-- v-if="nature == '建设单位'" -->
                    <el-button type="primary" v-if="yj_save" icon="el-icon-search" size="small" @click="yj_saveForm">保存
                    </el-button>
                </div>
            </div>
            <!-- 表格 -->
            <div class="text_table editTableAlarm">


                <tableData :config="table_config" :currentRow="false" :dataList="tableData" :loading="listLoading"
                    @inputValue="inputValue" statusType="1" />


            </div>

        </div>
    </div>
</template>
<script>
import tree from '@/components/public/common-trees';
import TableData from '@/components/public/el-tables';
import elBreadcrumb from "@/components/public/el-breadcrumb.vue"
// import publicForm from "@/components/public/el-form.vue"
import {
    getUserCompanyTreeList,//树状图接口
    saveStationWarn,// 查询-拌合站预警信息-新增接口
    getStationWarnByCompanyId,// 查询-拌合站预警信息-详情接口
} from "@/api/request.js";
import { statusType } from '@/utils/config';//配置项
export default {
    name: "Home",
    data() {
        return {
            name: "alarmParameterSetting",//按钮配置页面代号
            nature: null,
            yj_save: null,
            formData: {},//新增编辑向后台传递对象

            // 拌和站列表配置项
            table_config: {
                classCell: true,
                thead: [
                    // {
                    //     label: '',
                    //     prop: 'name',
                    //     minWidth: '30px',
                    //     align: "center"
                    // },
                    {
                        label: '',
                        prop: 'name',
                        minWidth: '30px',


                        filter: true,
                        btn: true,
                        align: "center",
                        colorName: '',
                        callback: (rowData) => {

                            let data = statusType[rowData.name]
                            if (data) {

                                return data.label
                            }
                        },
                        specialClass: (rowData) => {
                            let data = statusType[rowData.name]
                            if (data) {
                                return data.className
                            }
                        }
                    },
                    {
                        label: '水(%)',
                        prop: 'water',
                        minWidth: '60px',
                        type: 'number',
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center"
                    },
                    {
                        label: '水泥(%)', prop: 'cement', minWidth: '60px', type: 'number',
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center"
                    },

                    {
                        label: '骨料(%)', prop: 'aggregate', minWidth: '60px', type: 'number',
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center"
                    },
                    {
                        label: '粉煤灰(%)', prop: 'flyash', minWidth: '60px', type: 'number',
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center"
                    },
                    {
                        label: '矿粉(%)', prop: 'oredesign', minWidth: '60px', type: 'number',
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center"
                    },
                    {
                        label: '外加剂(%)', prop: 'admixture', minWidth: '60px', type: 'number',
                        disabled: false, //是否禁用
                        edit: true,
                        align: "center"
                    },
                    {
                        label: '闭合流程', prop: 'examine', minWidth: '60px', type: 'option',
                        disabled: false, //是否禁用
                        option: true,
                        align: "center",
                        options: [
                            {
                                value: '无需闭合',
                                label: '无需闭合'
                            },
                            {
                                value: '一级流程',
                                label: '一级流程'
                            }, {
                                value: '二级流程',
                                label: '二级流程',

                            }, {
                                value: '三级流程',
                                label: '三级流程',

                            },
                        ],
                    },


                ],
                isCheckBox: false,
                isIndex: false,
                isOperation: true,

            },
            tableData: [], //表格列表数据列表
            detailData: {},//拌合站预警信息-详情
            highlightBd: true, //左侧机构树停留背景色
            treelength: false, //左侧树显示隐藏
            checked: true, //查看下级
            showName: "未选择公司",
            dialogHeight: "330px",//新增编辑弹框高度
            fId: null, //点击当前列表数据fId
            listLoading: false,//列表数据加载loading
            loadingEditDialog: false,//弹框loading
            dialogEditVisible: false,//新增弹框是否显示
            // 列表给后端传参
            getList: {
                companyId: "",// 施工标段id
            },

            companyTree: "", //所有数据
            treeData: [], //左侧树状图数据

            // 左侧机构树
            defaultProps: {
                children: "children",
                label: "fShortname",
            },
            userInfo: {}, //登录用户
            checkData: [],
            treeText: {//树状图参数
                companyId: null,
                userId: null,
            },
        };
    },
    components: {
        tree,//左侧组织机构数
        TableData,//主页面列表
        elBreadcrumb,//面包屑
        // publicForm,//弹框表格
    },
    mounted() {
        this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
        if (JSON.parse(sessionStorage.getItem("yjSmart-currencyList"))) {
            var id = JSON.parse(sessionStorage.getItem("yjSmart-currencyList"));
            this.checkData = [id.fCompanyid];
        }
        this.getTree();
        this.btnRole(this.name);
    },
    methods: {
        btnRole(name) {// 按钮权限
            var btnList = [];
            var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
            if (ModuleList.length > 0) {
                ModuleList.map((item) => {
                    if (item.fEncode == name) {
                        btnList = item.modulebuttonList;
                    }
                });
                var btnStr = [];
                btnList.map((item) => {

                    btnStr.push(item.fEncode);
                });
                this.yj_save = btnStr.includes("yj_save");
            } else {
                this.yj_save = true;
            }
        },
        // 点击列表当前行，获取当前信息
        rowChange(row) {
            this.fId = row.fId;
        },
        // 左侧树结构
        getTree() {
            this.treeText.companyId = this.userInfo.companyId;
            this.treeText.userId = this.userInfo.userId;
            getUserCompanyTreeList(this.treeText)
                .then((res) => {
                    if (res.errcode == 0) {
                        var companyTree = res.data.userCompanyTreeList;
                        this.treeData = this.commonJs.tranListToTreeData(companyTree);


                        if (this.treeData[0].children == undefined) {
                            this.treelength = false;//左侧组织机构是否显示
                        }
                        else {
                            this.treelength = true;
                        }
                        // this.showName = this.treeData[0].fShortname;//当前点击组织机构名称
                        // this.getList.companyId = this.treeData[0].fCompanyid;//当前点击组织机构ID
                        // this.nature = this.treeData[0].fNature

                        if (this.checkData[0]) {
                            this.showName = JSON.parse(sessionStorage.getItem("yjSmart-currencyList")).fShortname

                            this.getList.companyId = this.checkData[0];
                            // this.nature = this.treeData[0].fNature

                        } else {
                            // this.nature = this.treeData[0].fNature

                            this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
                            this.getList.companyId = this.treeData[0].fCompanyid; //当前点击组织机构ID
                        }

                        // if (this.treeData[0].fNature == '建设单位') {

                        this.yj_searchForm(this.getList);// 调用主页面列表接口
                        // }

                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch(() => {
                    return false;
                });
        },

        // 点击左侧机构树
        handleNodeClick(data) {
            this.showName = data.fShortname; //顶部显示机构名
            this.getList.companyId = data.fCompanyid;
            this.nature = data.fNature
            // console.log(data.fNature);
            // if (data.fNature == '建设单位') {
            this.yj_searchForm(this.getList);
            // } else {
            //     this.tableData = []
            // }

        },
        tranListToTreeDatas(data) {//处理主页面列表树结构
            let result = [];
            if (!Array.isArray(data)) {
                return result;
            }
            // 清除已存在的数据  重新赋值
            data.forEach((item) => {
                delete item.children;
            });
            let map = {};
            data.forEach((item) => {
                map[item.fMachineid] = item;
            });
            data.forEach((item) => {
                let parent = map[item.fStationid];
                if (parent) {
                    (parent.children || (parent.children = [])).push(item);
                } else {
                    result.push(item);
                }
            });
            return result;
        },
        // 获取列表数据
        yj_searchForm(data) {
            this.listLoading = true;
            getStationWarnByCompanyId(data)
                .then((res) => {
                    if (res.errcode == 0) {
                        console.log(res);
                        var that = this;
                        that.listLoading = false;
                        var list = res.data.yjQmpMsStationwarn
                        this.formData = list
                        this.detailData = res.data.yjQmpMsStationwarn
                        this.tableData = [{
                            name: "1",
                            water: list.fWaterwarn1,//水
                            cement: list.fCementwarn1,//水泥
                            aggregate: list.fAggregatewarn1,//骨料(%)
                            flyash: list.fFlyashwarn1,//粉煤灰
                            oredesign: list.fGgbswarn1,//矿粉
                            admixture: list.fAdmixture1,//外加剂
                            examine: list.fExamine1//闭合流程

                        }, {
                            name: "2",
                            water: list.fWaterwarn2,//水
                            cement: list.fCementwarn2,//水泥
                            aggregate: list.fAggregatewarn2,//骨料(%)
                            flyash: list.fFlyashwarn2,//粉煤灰
                            oredesign: list.fGgbswarn2,//矿粉
                            admixture: list.fAdmixture2,//外加剂
                            examine: list.fExamine2//闭合流程
                        }, {
                            name: "3",
                            water: list.fWaterwarn3,//水
                            cement: list.fCementwarn3,//水泥
                            aggregate: list.fAggregatewarn3,//骨料(%)
                            flyash: list.fFlyashwarn3,//粉煤灰
                            oredesign: list.fGgbswarn3,//矿粉
                            admixture: list.fAdmixture3,//外加剂
                            examine: list.fExamine3//闭合流程
                        }]
                        // that.tableData = that.tranListToTreeDatas(res.data.yjQmpMsStationwarn)
                    } else {
                        this.$message.error(res.msg);
                        return false;
                    }
                })
                .catch((error) => {
                    console.log(error);
                });
        },

        // 保存接口
        yj_saveForm() {

            saveStationWarn(this.formData)
                .then((res) => {
                    if (res.errcode == 0) {
                        console.log(res);
                        this.yj_searchForm(this.getList);
                        this.$message.success("保存成功");
                    } else {
                        this.$message.error(res.msg);
                        console.log("接口报错");
                    }
                })
                .catch((error) => {
                    console.log("报警参数设置-新增）", error);
                });
        },

        // 关闭新增编辑弹框
        resetForm() {
            this.dialogEditVisible = false;
        },
        // 类型改变时触发
        changeRadio(num) {
            if (num == 0) {
                this.formObj[1].disabled = true
                this.formObj[1].rules[0].required = false
            } else {
                this.formObj[1].disabled = false
                this.formObj[1].rules[0].required = true
            }
        },
        // 拌合站下拉框
        selectChange(value) {
            this.formData.fStationid = value.value// 拌合站id
            this.formData.fStationname = value.label// 拌合站名称
        },
        // 骨料详情
        inputValue(val, table) {
            // console.log(val, table);
            this.formData = {
                fId: this.detailData.fId,// 主键id
                fCompanyid: this.getList.companyId,// 施工单位id
                fCompanyname: this.showName,//施工单位
                fWaterwarn1: table[0].water,// 水(%) 低预警
                fWaterwarn2: table[1].water,// 水(%) 中预警
                fWaterwarn3: table[2].water,// 水(%) 高预警
                fCementwarn1: table[0].cement,// 水泥(%) 低预警
                fCementwarn2: table[1].cement,// 水泥(%) 中预警
                fCementwarn3: table[2].cement,// 水泥(%) 高预警
                fAggregatewarn1: table[0].aggregate,// 粗细骨料(%) 低预警
                fAggregatewarn2: table[1].aggregate,// 粗细骨料(%) 中预警
                fAggregatewarn3: table[2].aggregate,// 粗细骨料(%) 高预警
                fFlyashwarn1: table[0].flyash,// 粉煤灰(%) 低预警
                fFlyashwarn2: table[1].flyash,// 粉煤灰(%) 中预警
                fFlyashwarn3: table[2].flyash,// 粉煤灰(%) 高预警
                fGgbswarn1: table[0].oredesign,// 矿粉(%) 低预警
                fGgbswarn2: table[1].oredesign,// 矿粉(%) 中预警
                fGgbswarn3: table[2].oredesign,// 矿粉(%) 高预警
                fAdmixture1: table[0].admixture,// 外加剂(%) 低预警
                fAdmixture2: table[1].admixture,// 外加剂(%) 中预警
                fAdmixture3: table[2].admixture,// 外加剂(%) 高预警
                fExamine1: table[0].examine,// 闭合流程 低预警
                fExamine2: table[1].examine,// 闭合流程 中预警
                fExamine3: table[2].examine,// 闭合流程 高预警
            }
            console.log(this.formData);

        },
        // classCell(row, column, rowIndex, columnIndex) {
        //     console.log(row, column, rowIndex, columnIndex);
        //     if (rowIndex == 0 && columnIndex == 0) {

        //         return 'blueClass';
        //     } else if (rowIndex == 1 && columnIndex == 0) {

        //         return 'orangeClass';
        //     } else if (rowIndex == 2 && columnIndex == 0) {

        //         return 'redClass';
        //     }
        // },
        // 多选方法
        selectionChange() { },
        // 排序方法
        sortChange() { },
        // 点击设备编码
        openDialog(row) {
            this.fId = row.F_Id;
            this.editText(this.fId);
        },
    },
};
</script>
  
<style scoped>
.printTables {
    background: #fff;
    display: flex;
    justify-content: end;
    padding: 5px;
    margin-top: 10px;
}

.dialogBody {
    padding: 3px 20px;
    height: 80%;
    overflow-y: auto;

}

.baseTitle {
    /* border: 1px solid #0c204d; */
    border-bottom: 1px solid #0c204d;

    height: 30px;
    line-height: 30px;
    position: relative;
    padding-left: 15px;

}

.baseTitle::after {
    display: block;
    content: "";
    height: 30px;
    width: 5px;
    position: absolute;
    left: 0;
    top: 0;
    background: #0c204d;
}
</style>